Page({
  data: {
    films: [],
    loading: true
  },

  onLoad: function () {
    this.fetchFilms();
  },

  fetchFilms: function () {
    const that = this;
    wx.request({
      url: 'http://8005.qizb.com/films',
      method: 'GET',
      success: function (res) {
        if (res.data && res.data.films) {
          that.setData({
            films: res.data.films,
            loading: false
          });
        }
      },
      fail: function (err) {
        console.error('获取电影数据失败:', err);
        wx.showToast({
          title: '加载失败',
          icon: 'none'
        });
        that.setData({
          loading: false
        });
      }
    });
  }
})